package com.example.share_doc.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.share_doc.controller.dto.UserPageDto;
import com.example.share_doc.entity.User;
import com.example.share_doc.service.UserService;
import com.example.share_doc.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/user")
@Tag(name = "用户接口")
public class UserController {

    private UserService userService;

    @PostMapping("/page")
    @Operation(summary = "用户分页")
    public R userPage(UserPageDto userPageDto){
        IPage page = userService.userPage(userPageDto);
        return R.success(page);
    }

    @PostMapping("/add")
    @Operation(summary = "用户新增/更新")
    public R userAdd(User user){
        userService.userAdd(user);
        return R.success(null);
    }

    @PostMapping("/deleteList")
    @Operation(summary = "用户批量删除")
    public R userDeleteList(List<String> userIdList){
        userService.userDeleteList(userIdList);
        return R.success(null);
    }

    @PostMapping("/login")
    @Operation(summary = "用户登录")
    public R userLogin(User user){
        user = userService.userLogin(user);
        return R.success(user);
    }
}
